import json

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from base.sqlalchemy import Base, SessionClass, JSONEncoder
from .config import DATABASE_URL, DEBUG

engine = create_engine(
    DATABASE_URL,
    isolation_level="READ COMMITTED",
    pool_recycle=3600,
    json_serializer=lambda obj: json.dumps(obj, cls=JSONEncoder),
    future=True,
    echo=DEBUG,
)

Session = sessionmaker(engine, class_=SessionClass)
